﻿//---------------------------------------------------------------
// Copyright (C) 2007 Microsoft Corporation. All rights reserved.
//---------------------------------------------------------------
var Splash = new function()
 {

	var splashEl, splashInnerEl, splashTitleEl, splashTextEl, splashButtonEl;

	var that=this;
	var m_timer;
	var m_onClose;
	this.title="";
	this.text="";
    
	this.initalize = function(p_el) {
 
		if (typeof p_el == "string") {
			p_el = document.getElementById(p_el);
		}
 
		var el;

		splashEl = p_el;
		splashEl.style.top=splashEl.style.left=""; //let CSS control top/left

		splashInnerEl = document.createElement("div");
		splashInnerEl.className = "splashInner";
		splashInnerEl.style.zIndex = splashEl.style.zIndex;

		splashTitleEl = document.createElement("div");
		splashTitleEl.className = "splashTitle";
		splashInnerEl.appendChild(splashTitleEl);

		splashTextEl = document.createElement("div");
		splashTextEl.className = "splashText";
		splashInnerEl.appendChild(splashTextEl);

		splashButtonEl = document.createElement("div");
		splashButtonEl.className = "splashButton";
		splashInnerEl.appendChild(splashButtonEl);

		el = document.createElement("button");
		el.innerHTML= "OK";
		el.onclick=hide;
		splashButtonEl.appendChild(el);

		hide();

		//and finally, add the whole thing to the DOM
		document.body.appendChild(splashInnerEl);
	};
    
	this.dispose = function() {
		if (m_timer) {clearTimeout(m_timer);} //stop if running
		m_timer=splashEl=splashTitleEl=splashTextEl=splashButtonEl=null;
	};

		
	this.show = function(p_title, p_msg, p_secs, p_showCloseButton, p_onClose) {

		if (m_timer) {clearTimeout(m_timer);} //stop if running

		splashEl.style.top=splashEl.style.left=""; //let CSS control top/left

		m_onClose = p_onClose;
		splashTitleEl.innerHTML = p_title;
		splashTextEl.innerHTML = p_msg;
		splashButtonEl.style.display = (p_showCloseButton?"block":"none"); //display close button?
		splashEl.style.display="block";
		splashInnerEl.style.display="block";
		splashEl.style.visibility="visible";
        splashTitleEl.style.visibility="visible";
		splashTextEl.style.visibility="visible";
		
		//setup an auto close timer?
		if (p_secs) {
			m_timer = setTimeout(hide, p_secs*1000);
		}
        
	};

	this.hide = function(p_secs, p_showCloseButton, p_onClose) {
		if (m_timer) {clearTimeout(m_timer);} //stop if running
        
		splashButtonEl.style.display = (p_showCloseButton?"block":"none"); //display close button?

		//setup an auto close timer?
		if (p_secs) {
			m_timer = setTimeout(hide, p_secs*1000);
		} else {
			hide();
		}
        
        
	};
	function hide() 
	{
		if (m_timer) {clearTimeout(m_timer);} //stop if running
		splashEl.style.display="none"; //hide the control
		splashInnerEl.style.display="none"; //hide the control
		splashEl.style.visibility="hidden";
		splashTitleEl.style.visibility="hidden";
		splashTextEl.style.visibility="hidden";
		if (m_onClose)
		{
			var tmpFn = m_onClose;
			m_onClose=null;
			tmpFn();
		}
	}
	
};


String.prototype.format=function(){
	var s=this;
	for (var i=0; i < arguments.length; i++){
		s=s.replace("{"+i+"}", arguments[i]);
	}
	return s;
};